﻿Public Class FrmProductBill
    Public FOpenType As String
    Private FPInfo As BServer.FBillPrintCFG
    Public FBid As String
    Private FBInfo As BServer.FBillProduct
    Private Sub FrmProductBill_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Icon = My.Resources.Properties
        SControl._Base_GetBillPrintConfig(UInfo.FSession, "Product", FPInfo, "")
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        Select Case FOpenType
            Case "NewBill"
                NewBill()
                FPrintBtn.Enabled = False
            Case "View"
                '--取单据信息
                If FBid Is Nothing Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If CInt(FBid) <= 0 Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If GetBillInfo() = False Then
                    MsgBox("读取单据信息失败!")
                    Dispose()
                    Return
                End If
                '-预留
                If FBinfo.FVid = Nothing Then
                    '-没审核
                    FSaveBtn.Text = "收费"
                    FSaveBtn.Image = My.Resources.money
                    FPrintBtn.Enabled = False
                ElseIf FBinfo.FVid = UInfo.id Then
                    FSaveBtn.Enabled = False
                    FPrintBtn.Enabled = True
                Else
                    '--其它人的单据
                    FSaveBtn.Enabled = False
                    FPrintBtn.Enabled = False
                End If
            Case Else
                MsgBox("参数错误")
                Dispose()
                Return
        End Select
    End Sub

    Private Sub ButtonX3_Click(sender As Object, e As EventArgs) Handles FCloseBtn.Click
        Dispose()
    End Sub

    Private Sub ButtonX5_Click(sender As Object, e As EventArgs) Handles FPagesetBtn.Click
        '--读取参数
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        '--显示页面设置窗口
        PageSetupDialog1.ShowDialog()
        '--保存参数
        Dim ps As New System.Drawing.Printing.PageSettings
        ps = PageSetupDialog1.PageSettings
        '---------参数赋值
        FPInfo.FMarginB = ps.Margins.Bottom
        FPInfo.FMarginT = ps.Margins.Top
        FPInfo.FMarginR = ps.Margins.Right
        FPInfo.FMarginL = ps.Margins.Left
        If ps.Landscape = False Then
            FPInfo.FPaperDirect = "V"
        Else
            FPInfo.FPaperDirect = "H"
        End If
        FPInfo.FPaperName = ps.PaperSize.PaperName
        FPInfo.FPrinterName = ps.PrinterSettings.PrinterName
        '---上传参数
        Dim ErrString As String = String.Empty
        If SControl._Base_SetBillConfig(UInfo.FSession, "Product", FPInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
    End Sub

    Private Sub ButtonX4_Click(sender As Object, e As EventArgs) Handles FPrintBtn.Click

        '--读取打印参数
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        Dim ps As New System.Drawing.Printing.PageSettings
        ps = PageSetupDialog1.PageSettings
        PrintDialog1.PrinterSettings = ps.PrinterSettings
        '--弹出打印设置窗口
        If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
            Return
        End If
        '--更新打印参数
        PrintDialog1.AllowPrintToFile = False
        ps.PrinterSettings = PrintDialog1.PrinterSettings
        '--保存打印参数
        FPInfo.FPaperName = ps.PaperSize.PaperName
        FPInfo.FPrinterName = ps.PrinterSettings.PrinterName
        '---上传参数
        Dim ErrString As String = String.Empty
        If SControl._Base_SetBillConfig(UInfo.FSession, "Product", FPInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
        '---显示预览
        PrintDocument1.DefaultPageSettings = ps
        PrintDocument1.DocumentName = "收款收据(三)"
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
        '--增加打印次数
    End Sub

    Private Sub PrintDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        '--打印设置
        '--A4纸
        PrintDocument1.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize With {.PaperName = "A4", .Height = 1169, .Width = 827}
        '--页面设置
        PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
        '--打印机设置
        PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
        '--设置以1/100英寸为单位
        e.Graphics.PageUnit = GraphicsUnit.Millimeter
        '--定义变量
        Dim g As Graphics = e.Graphics
        Dim FX As Integer = FPInfo.FMarginL
        Dim FY As Integer = FPInfo.FMarginR
        Dim rect As Rectangle = Nothing
        Dim fnt As Font = New Font("宋体", 20, FontStyle.Bold)
        '--绘制表格
        '-标题下方两条直线
        g.PageUnit = GraphicsUnit.Display
        g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(80 + FX), FControl.CalcInch(8.2 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(8.2 + FY))
        g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(80 + FX), FControl.CalcInch(9.5 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(9.5 + FY))
        '-主单据框
        rect = New Rectangle(New Point(FControl.CalcInch(26 + FX), FControl.CalcInch(29 + FY)), New Size(FControl.CalcInch(148), FControl.CalcInch(46)))
        g.DrawRectangle(Pens.Black, rect)
        '-横线
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(36 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(36 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(42 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(49 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(49 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(55 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(62 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(62 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(68 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(68 + FY))
        '-竖线
        g.DrawLine(Pens.Black, FControl.CalcInch(54.5 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(54.5 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(76 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(76 + FX), FControl.CalcInch(68 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(95 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(95 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(114 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(114 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(141 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(174 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(75 + FY))
        g.PageUnit = GraphicsUnit.Millimeter
        '-右侧标记
        fnt = New Font("宋体", 12)
        g.DrawString("①", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 37 + FY})
        g.DrawString("记", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 43 + FY})
        g.DrawString("账", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 48 + FY})
        g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 53 + FY})
        '--单据头
        fnt = New Font("宋体", 20)
        g.DrawString(FCaptionLabel.Text.Trim, fnt, Brushes.Black, 90 + FX, 0 + FY)
        fnt = New Font("宋体", 12)
        g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, 85 + FX, 12 + FY)
        g.DrawString("交款单位: " & FNameBox.Text, fnt, Brushes.Black, 27 + FX, 18 + FY)
        g.DrawString("交 款 人: " & FCNameBox.Text, fnt, Brushes.Black, 27 + FX, 24 + FY)
        g.DrawString("编  号: " & FBillNoBox.Text, fnt, Brushes.Black, 121 + FX, 18 + FY)
        g.DrawString("验证码: " & FVerifyBox.Text, fnt, Brushes.Black, 121 + FX, 24 + FY)
        '--表单标题
        g.DrawString("品名", fnt, Brushes.Black, 37 + FX, 31 + FY)
        g.DrawString("单位", fnt, Brushes.Black, 61 + FX, 31 + FY)
        g.DrawString("数量", fnt, Brushes.Black, 81 + FX, 31 + FY)
        g.DrawString("单价", fnt, Brushes.Black, 100 + FX, 31 + FY)
        g.DrawString("金额", fnt, Brushes.Black, 123 + FX, 31 + FY)
        g.DrawString("备注", fnt, Brushes.Black, 153 + FX, 31 + FY)
        '--单据尾
        g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 25 + FX, 77 + FY)
        '--内容
        '-第一行
        g.DrawString(FItem1Box.Text, fnt, Brushes.Black, 27 + FX, 36.5 + FY)
        g.DrawString(FUnit1Box.Text, fnt, Brushes.Black, 55.5 + FX, 36.5 + FY)
        g.DrawString(FQty1Box.Value, fnt, Brushes.Black, 77 + FX, 36.5 + FY)
        g.DrawString(FPrice1Box.Value, fnt, Brushes.Black, 96 + FX, 36.5 + FY)
        g.DrawString(FAcc1Box.Value, fnt, Brushes.Black, 115 + FX, 36.5 + FY)
        g.DrawString(FMark1Box.Text, fnt, Brushes.Black, 142 + FX, 36.5 + FY)

        '-第二行
        g.DrawString(FItem2Box.Text, fnt, Brushes.Black, 27 + FX, 43.5 + FY)
        g.DrawString(FUnit2Box.Text, fnt, Brushes.Black, 55.5 + FX, 43.5 + FY)
        g.DrawString(FQty2Box.Value, fnt, Brushes.Black, 77 + FX, 43.5 + FY)
        g.DrawString(FPrice2Box.Value, fnt, Brushes.Black, 96 + FX, 43.5 + FY)
        g.DrawString(FAcc2Box.Value, fnt, Brushes.Black, 115 + FX, 43.5 + FY)
        g.DrawString(FMark2Box.Text, fnt, Brushes.Black, 142 + FX, 43.5 + FY)

        '-第三行
        g.DrawString(FItem3Box.Text, fnt, Brushes.Black, 27 + FX, 50 + FY)
        g.DrawString(FUnit3Box.Text, fnt, Brushes.Black, 55.5 + FX, 50 + FY)
        g.DrawString(FQty3Box.Value, fnt, Brushes.Black, 77 + FX, 50 + FY)
        g.DrawString(FPrice3Box.Value, fnt, Brushes.Black, 96 + FX, 50 + FY)
        g.DrawString(FAcc3Box.Value, fnt, Brushes.Black, 115 + FX, 50 + FY)
        g.DrawString(FMark3Box.Text, fnt, Brushes.Black, 142 + FX, 50 + FY)

        '-第四行
        g.DrawString(FItem4Box.Text, fnt, Brushes.Black, 27 + FX, 56.5 + FY)
        g.DrawString(FUnit4Box.Text, fnt, Brushes.Black, 55.5 + FX, 56.5 + FY)
        g.DrawString(FQty4Box.Value, fnt, Brushes.Black, 77 + FX, 56.5 + FY)
        g.DrawString(FPrice4Box.Value, fnt, Brushes.Black, 96 + FX, 56.5 + FY)
        g.DrawString(FAcc4Box.Value, fnt, Brushes.Black, 115 + FX, 56.5 + FY)
        g.DrawString(FMark4Box.Text, fnt, Brushes.Black, 142 + FX, 56.5 + FY)

        '-第五行
        g.DrawString(FItem5Box.Text, fnt, Brushes.Black, 27 + FX, 63 + FY)
        g.DrawString(FUnit5Box.Text, fnt, Brushes.Black, 55.5 + FX, 63 + FY)
        g.DrawString(FQty5Box.Value, fnt, Brushes.Black, 77 + FX, 63 + FY)
        g.DrawString(FPrice5Box.Value, fnt, Brushes.Black, 96 + FX, 63 + FY)
        g.DrawString(FAcc5Box.Value, fnt, Brushes.Black, 115 + FX, 63 + FY)
        g.DrawString(FMark5Box.Text, fnt, Brushes.Black, 142 + FX, 63 + FY)

        '-汇总行
        g.DrawString("合计(大写):", fnt, Brushes.Black, 27 + FX, 70 + FY)
        g.DrawString(FAmountBigLabel.Text, fnt, Brushes.Black, 55.5 + FX, 70 + FY)
        g.DrawString("合计:", fnt, Brushes.Black, 96 + FX, 70 + FY)
        g.DrawString(FAmountLabel.Text, fnt, Brushes.Black, 115 + FX, 70 + FY)

        '-----------------------第一段结束-----------------------------------

        FY += 95
        '--绘制表格
        '-标题下方两条直线
        g.PageUnit = GraphicsUnit.Display
        g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(80 + FX), FControl.CalcInch(8.2 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(8.2 + FY))
        g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(80 + FX), FControl.CalcInch(9.5 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(9.5 + FY))
        '-主单据框
        rect = New Rectangle(New Point(FControl.CalcInch(26 + FX), FControl.CalcInch(29 + FY)), New Size(FControl.CalcInch(148), FControl.CalcInch(46)))
        g.DrawRectangle(Pens.Black, rect)
        '-横线
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(36 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(36 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(42 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(49 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(49 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(55 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(62 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(62 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(68 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(68 + FY))
        '-竖线
        g.DrawLine(Pens.Black, FControl.CalcInch(54.5 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(54.5 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(76 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(76 + FX), FControl.CalcInch(68 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(95 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(95 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(114 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(114 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(141 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(174 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(75 + FY))
        g.PageUnit = GraphicsUnit.Millimeter
        '-右侧标记
        fnt = New Font("宋体", 12)
        g.DrawString("②", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 37 + FY})
        g.DrawString("客", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 43 + FY})
        g.DrawString("户", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 48 + FY})
        g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 53 + FY})
        '--单据头
        fnt = New Font("宋体", 20)
        g.DrawString(FCaptionLabel.Text.Trim, fnt, Brushes.Black, 90 + FX, 0 + FY)
        fnt = New Font("宋体", 12)
        g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, 85 + FX, 12 + FY)
        g.DrawString("交款单位: " & FNameBox.Text, fnt, Brushes.Black, 27 + FX, 18 + FY)
        g.DrawString("交 款 人: " & FCNameBox.Text, fnt, Brushes.Black, 27 + FX, 24 + FY)
        g.DrawString("编  号: " & FBillNoBox.Text, fnt, Brushes.Black, 121 + FX, 18 + FY)
        g.DrawString("验证码: " & FVerifyBox.Text, fnt, Brushes.Black, 121 + FX, 24 + FY)
        '--表单标题
        g.DrawString("品名", fnt, Brushes.Black, 37 + FX, 31 + FY)
        g.DrawString("单位", fnt, Brushes.Black, 61 + FX, 31 + FY)
        g.DrawString("数量", fnt, Brushes.Black, 81 + FX, 31 + FY)
        g.DrawString("单价", fnt, Brushes.Black, 100 + FX, 31 + FY)
        g.DrawString("金额", fnt, Brushes.Black, 123 + FX, 31 + FY)
        g.DrawString("备注", fnt, Brushes.Black, 153 + FX, 31 + FY)
        '--单据尾
        g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 25 + FX, 77 + FY)
        '--内容
        '-第一行
        g.DrawString(FItem1Box.Text, fnt, Brushes.Black, 27 + FX, 36.5 + FY)
        g.DrawString(FUnit1Box.Text, fnt, Brushes.Black, 55.5 + FX, 36.5 + FY)
        g.DrawString(FQty1Box.Value, fnt, Brushes.Black, 77 + FX, 36.5 + FY)
        g.DrawString(FPrice1Box.Value, fnt, Brushes.Black, 96 + FX, 36.5 + FY)
        g.DrawString(FAcc1Box.Value, fnt, Brushes.Black, 115 + FX, 36.5 + FY)
        g.DrawString(FMark1Box.Text, fnt, Brushes.Black, 142 + FX, 36.5 + FY)

        '-第二行
        g.DrawString(FItem2Box.Text, fnt, Brushes.Black, 27 + FX, 43.5 + FY)
        g.DrawString(FUnit2Box.Text, fnt, Brushes.Black, 55.5 + FX, 43.5 + FY)
        g.DrawString(FQty2Box.Value, fnt, Brushes.Black, 77 + FX, 43.5 + FY)
        g.DrawString(FPrice2Box.Value, fnt, Brushes.Black, 96 + FX, 43.5 + FY)
        g.DrawString(FAcc2Box.Value, fnt, Brushes.Black, 115 + FX, 43.5 + FY)
        g.DrawString(FMark2Box.Text, fnt, Brushes.Black, 142 + FX, 43.5 + FY)

        '-第三行
        g.DrawString(FItem3Box.Text, fnt, Brushes.Black, 27 + FX, 50 + FY)
        g.DrawString(FUnit3Box.Text, fnt, Brushes.Black, 55.5 + FX, 50 + FY)
        g.DrawString(FQty3Box.Value, fnt, Brushes.Black, 77 + FX, 50 + FY)
        g.DrawString(FPrice3Box.Value, fnt, Brushes.Black, 96 + FX, 50 + FY)
        g.DrawString(FAcc3Box.Value, fnt, Brushes.Black, 115 + FX, 50 + FY)
        g.DrawString(FMark3Box.Text, fnt, Brushes.Black, 142 + FX, 50 + FY)

        '-第四行
        g.DrawString(FItem4Box.Text, fnt, Brushes.Black, 27 + FX, 56.5 + FY)
        g.DrawString(FUnit4Box.Text, fnt, Brushes.Black, 55.5 + FX, 56.5 + FY)
        g.DrawString(FQty4Box.Value, fnt, Brushes.Black, 77 + FX, 56.5 + FY)
        g.DrawString(FPrice4Box.Value, fnt, Brushes.Black, 96 + FX, 56.5 + FY)
        g.DrawString(FAcc4Box.Value, fnt, Brushes.Black, 115 + FX, 56.5 + FY)
        g.DrawString(FMark4Box.Text, fnt, Brushes.Black, 142 + FX, 56.5 + FY)

        '-第五行
        g.DrawString(FItem5Box.Text, fnt, Brushes.Black, 27 + FX, 63 + FY)
        g.DrawString(FUnit5Box.Text, fnt, Brushes.Black, 55.5 + FX, 63 + FY)
        g.DrawString(FQty5Box.Value, fnt, Brushes.Black, 77 + FX, 63 + FY)
        g.DrawString(FPrice5Box.Value, fnt, Brushes.Black, 96 + FX, 63 + FY)
        g.DrawString(FAcc5Box.Value, fnt, Brushes.Black, 115 + FX, 63 + FY)
        g.DrawString(FMark5Box.Text, fnt, Brushes.Black, 142 + FX, 63 + FY)

        '-汇总行
        g.DrawString("合计(大写):", fnt, Brushes.Black, 27 + FX, 70 + FY)
        g.DrawString(FAmountBigLabel.Text, fnt, Brushes.Black, 55.5 + FX, 70 + FY)
        g.DrawString("合计:", fnt, Brushes.Black, 96 + FX, 70 + FY)
        g.DrawString(FAmountLabel.Text, fnt, Brushes.Black, 115 + FX, 70 + FY)

        '---------------------------第二段结束-----------------------------------

        FY += 95
        '--绘制表格
        '-标题下方两条直线
        g.PageUnit = GraphicsUnit.Display
        g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(80 + FX), FControl.CalcInch(8.2 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(8.2 + FY))
        g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(80 + FX), FControl.CalcInch(9.5 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(9.5 + FY))
        '-主单据框
        rect = New Rectangle(New Point(FControl.CalcInch(26 + FX), FControl.CalcInch(29 + FY)), New Size(FControl.CalcInch(148), FControl.CalcInch(46)))
        g.DrawRectangle(Pens.Black, rect)
        '-横线
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(36 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(36 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(42 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(42 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(49 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(49 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(55 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(55 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(62 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(62 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(26 + FX), FControl.CalcInch(68 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(68 + FY))
        '-竖线
        g.DrawLine(Pens.Black, FControl.CalcInch(54.5 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(54.5 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(76 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(76 + FX), FControl.CalcInch(68 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(95 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(95 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(114 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(114 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(141 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(141 + FX), FControl.CalcInch(75 + FY))
        g.DrawLine(Pens.Black, FControl.CalcInch(174 + FX), FControl.CalcInch(29 + FY), FControl.CalcInch(174 + FX), FControl.CalcInch(75 + FY))
        g.PageUnit = GraphicsUnit.Millimeter
        '-右侧标记
        fnt = New Font("宋体", 12)
        g.DrawString("③", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 37 + FY})
        g.DrawString("其", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 43 + FY})
        g.DrawString("它", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 48 + FY})
        g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 53 + FY})
        '--单据头
        fnt = New Font("宋体", 20)
        g.DrawString(FCaptionLabel.Text.Trim, fnt, Brushes.Black, 90 + FX, 0 + FY)
        fnt = New Font("宋体", 12)
        g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, 85 + FX, 12 + FY)
        g.DrawString("交款单位: " & FNameBox.Text, fnt, Brushes.Black, 27 + FX, 18 + FY)
        g.DrawString("交 款 人: " & FCNameBox.Text, fnt, Brushes.Black, 27 + FX, 24 + FY)
        g.DrawString("编  号: " & FBillNoBox.Text, fnt, Brushes.Black, 121 + FX, 18 + FY)
        g.DrawString("验证码: " & FVerifyBox.Text, fnt, Brushes.Black, 121 + FX, 24 + FY)
        '--表单标题
        g.DrawString("品名", fnt, Brushes.Black, 37 + FX, 31 + FY)
        g.DrawString("单位", fnt, Brushes.Black, 61 + FX, 31 + FY)
        g.DrawString("数量", fnt, Brushes.Black, 81 + FX, 31 + FY)
        g.DrawString("单价", fnt, Brushes.Black, 100 + FX, 31 + FY)
        g.DrawString("金额", fnt, Brushes.Black, 123 + FX, 31 + FY)
        g.DrawString("备注", fnt, Brushes.Black, 153 + FX, 31 + FY)
        '--单据尾
        g.DrawString(String.Format("收款单位章:     收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 25 + FX, 77 + FY)
        '--内容
        '-第一行
        g.DrawString(FItem1Box.Text, fnt, Brushes.Black, 27 + FX, 36.5 + FY)
        g.DrawString(FUnit1Box.Text, fnt, Brushes.Black, 55.5 + FX, 36.5 + FY)
        g.DrawString(FQty1Box.Value, fnt, Brushes.Black, 77 + FX, 36.5 + FY)
        g.DrawString(FPrice1Box.Value, fnt, Brushes.Black, 96 + FX, 36.5 + FY)
        g.DrawString(FAcc1Box.Value, fnt, Brushes.Black, 115 + FX, 36.5 + FY)
        g.DrawString(FMark1Box.Text, fnt, Brushes.Black, 142 + FX, 36.5 + FY)

        '-第二行
        g.DrawString(FItem2Box.Text, fnt, Brushes.Black, 27 + FX, 43.5 + FY)
        g.DrawString(FUnit2Box.Text, fnt, Brushes.Black, 55.5 + FX, 43.5 + FY)
        g.DrawString(FQty2Box.Value, fnt, Brushes.Black, 77 + FX, 43.5 + FY)
        g.DrawString(FPrice2Box.Value, fnt, Brushes.Black, 96 + FX, 43.5 + FY)
        g.DrawString(FAcc2Box.Value, fnt, Brushes.Black, 115 + FX, 43.5 + FY)
        g.DrawString(FMark2Box.Text, fnt, Brushes.Black, 142 + FX, 43.5 + FY)

        '-第三行
        g.DrawString(FItem3Box.Text, fnt, Brushes.Black, 27 + FX, 50 + FY)
        g.DrawString(FUnit3Box.Text, fnt, Brushes.Black, 55.5 + FX, 50 + FY)
        g.DrawString(FQty3Box.Value, fnt, Brushes.Black, 77 + FX, 50 + FY)
        g.DrawString(FPrice3Box.Value, fnt, Brushes.Black, 96 + FX, 50 + FY)
        g.DrawString(FAcc3Box.Value, fnt, Brushes.Black, 115 + FX, 50 + FY)
        g.DrawString(FMark3Box.Text, fnt, Brushes.Black, 142 + FX, 50 + FY)

        '-第四行
        g.DrawString(FItem4Box.Text, fnt, Brushes.Black, 27 + FX, 56.5 + FY)
        g.DrawString(FUnit4Box.Text, fnt, Brushes.Black, 55.5 + FX, 56.5 + FY)
        g.DrawString(FQty4Box.Value, fnt, Brushes.Black, 77 + FX, 56.5 + FY)
        g.DrawString(FPrice4Box.Value, fnt, Brushes.Black, 96 + FX, 56.5 + FY)
        g.DrawString(FAcc4Box.Value, fnt, Brushes.Black, 115 + FX, 56.5 + FY)
        g.DrawString(FMark4Box.Text, fnt, Brushes.Black, 142 + FX, 56.5 + FY)

        '-第五行
        g.DrawString(FItem5Box.Text, fnt, Brushes.Black, 27 + FX, 63 + FY)
        g.DrawString(FUnit5Box.Text, fnt, Brushes.Black, 55.5 + FX, 63 + FY)
        g.DrawString(FQty5Box.Value, fnt, Brushes.Black, 77 + FX, 63 + FY)
        g.DrawString(FPrice5Box.Value, fnt, Brushes.Black, 96 + FX, 63 + FY)
        g.DrawString(FAcc5Box.Value, fnt, Brushes.Black, 115 + FX, 63 + FY)
        g.DrawString(FMark5Box.Text, fnt, Brushes.Black, 142 + FX, 63 + FY)

        '-汇总行
        g.DrawString("合计(大写):", fnt, Brushes.Black, 27 + FX, 70 + FY)
        g.DrawString(FAmountBigLabel.Text, fnt, Brushes.Black, 55.5 + FX, 70 + FY)
        g.DrawString("合计:", fnt, Brushes.Black, 96 + FX, 70 + FY)
        g.DrawString(FAmountLabel.Text, fnt, Brushes.Black, 115 + FX, 70 + FY)
    End Sub

    Private Sub FItem1Box_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FItem1Box.SelectedIndexChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim FCinf As New BServer.FBaseProduct With {.id = FItem1Box.SelectedValue, .FType = 1, .FName = FItem1Box.Text}
            Dim ErrString As String = String.Empty
            If SControl._BILL_Product_GetBaseInfo(UInfo.FSession, FCinf, ErrString) = False Then
                Return
            End If
            FUnit1Box.Text = FCinf.FUnit
            FPrice1Box.Value = FCinf.FPrice
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FItem2Box_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FItem2Box.SelectedIndexChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim FCinf As New BServer.FBaseProduct With {.id = FItem2Box.SelectedValue, .FType = 1, .FName = FItem2Box.Text}
            Dim ErrString As String = String.Empty
            If SControl._BILL_Product_GetBaseInfo(UInfo.FSession, FCinf, ErrString) = False Then
                Return
            End If
            FUnit2Box.Text = FCinf.FUnit
            FPrice2Box.Value = FCinf.FPrice
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FItem3Box_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FItem3Box.SelectedIndexChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim FCinf As New BServer.FBaseProduct With {.id = FItem3Box.SelectedValue, .FType = 1, .FName = FItem3Box.Text}
            Dim ErrString As String = String.Empty
            If SControl._BILL_Product_GetBaseInfo(UInfo.FSession, FCinf, ErrString) = False Then
                Return
            End If
            FUnit3Box.Text = FCinf.FUnit
            FPrice3Box.Value = FCinf.FPrice
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FItem4Box_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FItem4Box.SelectedIndexChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim FCinf As New BServer.FBaseProduct With {.id = FItem4Box.SelectedValue, .FType = 1, .FName = FItem4Box.Text}
            Dim ErrString As String = String.Empty
            If SControl._BILL_Product_GetBaseInfo(UInfo.FSession, FCinf, ErrString) = False Then
                Return
            End If
            FUnit4Box.Text = FCinf.FUnit
            FPrice4Box.Value = FCinf.FPrice
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FItem5Box_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FItem5Box.SelectedIndexChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim FCinf As New BServer.FBaseProduct With {.id = FItem5Box.SelectedValue, .FType = 1, .FName = FItem5Box.Text}
            Dim ErrString As String = String.Empty
            If SControl._BILL_Product_GetBaseInfo(UInfo.FSession, FCinf, ErrString) = False Then
                Return
            End If
            FUnit5Box.Text = FCinf.FUnit
            FPrice5Box.Value = FCinf.FPrice
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FQty1Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty1Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc1Box.Value = FQty1Box.Value * FPrice1Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FPrice1Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice1Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc1Box.Value = FQty1Box.Value * FPrice1Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FQty2Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty2Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc2Box.Value = FQty2Box.Value * FPrice2Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FPrice2Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice2Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc2Box.Value = FQty2Box.Value * FPrice2Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FQty3Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc3Box.Value = FQty3Box.Value * FPrice3Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FPrice3Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc3Box.Value = FQty3Box.Value * FPrice3Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FQty4Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty4Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc4Box.Value = FQty4Box.Value * FPrice4Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FPrice4Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice4Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc4Box.Value = FQty4Box.Value * FPrice4Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FQty5Box_ValueChanged(sender As Object, e As EventArgs) Handles FQty5Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc5Box.Value = FQty5Box.Value * FPrice5Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FPrice5Box_ValueChanged(sender As Object, e As EventArgs) Handles FPrice5Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FAcc5Box.Value = FQty5Box.Value * FPrice5Box.Value
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FAcc1Box_ValueChanged(sender As Object, e As EventArgs) Handles FAcc1Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim s As Double = 0
            If FItem1Box.Text.Trim <> String.Empty Then
                s += FAcc1Box.Value
            End If
            If FItem2Box.Text.Trim <> String.Empty Then
                s += FAcc2Box.Value
            End If
            If FItem3Box.Text.Trim <> String.Empty Then
                s += FAcc3Box.Value
            End If
            If FItem4Box.Text.Trim <> String.Empty Then
                s += FAcc4Box.Value
            End If
            If FItem5Box.Text.Trim <> String.Empty Then
                s += FAcc5Box.Value
            End If
            FAmountLabel.Text = s
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FAcc2Box_ValueChanged(sender As Object, e As EventArgs) Handles FAcc2Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim s As Double = 0
            If FItem1Box.Text.Trim <> String.Empty Then
                s += FAcc1Box.Value
            End If
            If FItem2Box.Text.Trim <> String.Empty Then
                s += FAcc2Box.Value
            End If
            If FItem3Box.Text.Trim <> String.Empty Then
                s += FAcc3Box.Value
            End If
            If FItem4Box.Text.Trim <> String.Empty Then
                s += FAcc4Box.Value
            End If
            If FItem5Box.Text.Trim <> String.Empty Then
                s += FAcc5Box.Value
            End If
            FAmountLabel.Text = s
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FAcc3Box_ValueChanged(sender As Object, e As EventArgs) Handles FAcc3Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim s As Double = 0
            If FItem1Box.Text.Trim <> String.Empty Then
                s += FAcc1Box.Value
            End If
            If FItem2Box.Text.Trim <> String.Empty Then
                s += FAcc2Box.Value
            End If
            If FItem3Box.Text.Trim <> String.Empty Then
                s += FAcc3Box.Value
            End If
            If FItem4Box.Text.Trim <> String.Empty Then
                s += FAcc4Box.Value
            End If
            If FItem5Box.Text.Trim <> String.Empty Then
                s += FAcc5Box.Value
            End If
            FAmountLabel.Text = s
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FAcc4Box_ValueChanged(sender As Object, e As EventArgs) Handles FAcc4Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim s As Double = 0
            If FItem1Box.Text.Trim <> String.Empty Then
                s += FAcc1Box.Value
            End If
            If FItem2Box.Text.Trim <> String.Empty Then
                s += FAcc2Box.Value
            End If
            If FItem3Box.Text.Trim <> String.Empty Then
                s += FAcc3Box.Value
            End If
            If FItem4Box.Text.Trim <> String.Empty Then
                s += FAcc4Box.Value
            End If
            If FItem5Box.Text.Trim <> String.Empty Then
                s += FAcc5Box.Value
            End If
            FAmountLabel.Text = s
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FAcc5Box_ValueChanged(sender As Object, e As EventArgs) Handles FAcc5Box.ValueChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim s As Double = 0
            If FItem1Box.Text.Trim <> String.Empty Then
                s += FAcc1Box.Value
            End If
            If FItem2Box.Text.Trim <> String.Empty Then
                s += FAcc2Box.Value
            End If
            If FItem3Box.Text.Trim <> String.Empty Then
                s += FAcc3Box.Value
            End If
            If FItem4Box.Text.Trim <> String.Empty Then
                s += FAcc4Box.Value
            End If
            If FItem5Box.Text.Trim <> String.Empty Then
                s += FAcc5Box.Value
            End If
            FAmountLabel.Text = s
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FNameBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FNameBox.SelectedIndexChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            FCNameBox.SelectedValue = FNameBox.SelectedValue
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FNameBox_TextChanged(sender As Object, e As EventArgs) Handles FNameBox.TextChanged
        If FOpenType = "View" Then
            Return
        End If
        Try
            Dim s As Integer = FNameBox.FindStringExact(FNameBox.Text)
            If s >= 0 Then
                If s <> FNameBox.SelectedIndex Then
                    FNameBox.SelectedIndex = s
                End If
            End If
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FAmountLabel_TextChanged(sender As Object, e As EventArgs) Handles FAmountLabel.TextChanged
        Try
            FAmountLabel.Text = CInt(FAmountLabel.Text)
            FAmountBigLabel.Text = FControl.MoneyToUpper(CDbl(FAmountLabel.Text))
        Catch ex As Exception
            Return
        End Try
    End Sub

    Private Sub FSaveBtn_Click(sender As Object, e As EventArgs) Handles FSaveBtn.Click
        SaveBill()
    End Sub
End Class